import java.util.*;
public class Main
{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int ret = -1; // 并没有回⽂串
        int n = s.length;
        for(int i = 0; i < n; i++) {
            if(i + 1 < n && s[i] == s[i + 1]) { // 判断⻓度为 2 的⼦串
                ret = 2;
                break;
            }
            if(i + 2 < n && s[i] == s[i + 2])  {// 判断⻓度为 3 的⼦串
                ret = 3;
            }
        }
        System.out.println(ret);
    }
}

